package com.kingschan.jeasytag.core.validation.properties.impl;
import java.lang.reflect.Field;
import com.kingschan.jeasytag.core.annotations.tag.*;
import com.kingschan.jeasytag.core.validation.properties.PropertiesValidation;
import com.kingschan.jeasytag.exception.PropertiesValidationException;
import com.kingschan.util.lang.StringUtil;
/**
 * StringFieldValidationImpl
 * @author kingschan
 *date:2013-7-11
 */
public class StringFieldValidationImpl implements PropertiesValidation {

	@Override
	public void validation(Field f, Object value)throws PropertiesValidationException {
		StringField s = f.getAnnotation(StringField.class);
		if (!"".equals(StringUtil.ConvertNullStr(s.Regex()))) {
			if (!value.toString().matches(s.Regex())) {
				throw new PropertiesValidationException(String.format("the Properties %s  must be matches % !", f.getName(),s.Regex()));
			}
		}
	}

}
